/*

Marinov Kinne

This version January 2012

Run .do file from same directory as data file

Export relevant data to .R scripts

*/

use "/Users/kinne/Desktop/CURRENT/Papers/hawksdoves/DATA2/Kinne_Marinov_JCR.dta", clear

/* Generate MID data variables, as per Weeks 2008 */
gen float recip=0replace recip=1 if cwhost2>1 /* cwhost2>1 picks up all instances in which the target responded with a militarized action */gen float capshare1=cap_1/(cap_1 + cap_2)gen float majmaj=0replace majmaj=1 if majpow1==1 &majpow2==1gen float majmin=0replace majmin=1 if majpow1==1 & majpow2==0gen float minmaj=0replace minmaj=1 if majpow1==0 & majpow2==1gen float revter=0replace revter=1 if cwrevt11==1gen float revpol=0replace revpol=1 if cwrevt11==2gen float revgov=0replace revgov=1 if cwrevt11== 3gen float revoth=0replace revoth=1 if cwrevt11==4/* Set contiguity measure */rename contig contig1gen contig=0replace contig=1 if contig1<6

/* Mark bilateral dyads */
gen bilateral=0replace bilateral=1 if cwnumst1==1 & cwnumst2==1

label var personal1 "personalist"
label var single1 "single-party"
label var majmaj "major-major"label var minmaj "minor-major"label var majmin "major-minor"label var capshare1 "capabilities share"label var contig "contiguous"label var s_wt_glo "alliance portfolio similarity"label var s_ld_1 "status quo evaluation i"label var s_ld_2 "status quo evaulation j"label var revter "territory"label var revgov "government or regime"label var revpol "policy"label var revoth "other"


****************************
* BEGIN EMPIRICAL ANALYSIS *
****************************


/* Basic frequency tables (described in paper, included only in online appendix) */
gen reg_3_1=3 if reg1==1replace reg_3_1=2 if anoalt1==1replace reg_3_1=1 if autalt1==1tab reg_3_1, summarize(recip)

/* With electoral authoritarianism broken down into two categories */
gen alt_3_1=4 if reg1==1replace alt_3_1=3 if demano1==1replace alt_3_1=2 if autano1==1
replace alt_3_1=1 if autalt1==1tab alt_3_1, summarize(recip)


**************************
* FIRST REGRESSION TABLE *
**************************
* Effect of democracylogit recip reg1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog* Alternate coding, still just three dummieslogit recip reg1 anoalt1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog

* Alternate coding, now with four dummy categorieslogit recip reg1 demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog

* Include only bilateral disputes
logit recip reg1 demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if bilateral==1, robust cluster(cwkeynum) nolog
* Two-way crossed random effects
* WARNING: THIS WILL TAKE A HALF HOUR OR SO TO ESTIMATE
* COMMENT THIS OUT UNLESS YOU WANT TO WAIT FOR IT...
* xtmelogit recip reg1 demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth || _all:R.ccodecow || ccodecow2:
* A simplified rule-of-three modellogit recip reg1 demano1 autano1, robust cluster(cwkeynum) nolog


***************************
* SECOND REGRESSION TABLE *
***************************

* Control for Weeks' single-party and personalist regimes
logit recip single1 personal1 reg1 demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog

* Now control for Schultz's competition variables and do some residual regressions for comparison
* First generate the competition dummy, following Schultz's rules
gen compsch=((parreg==2 | parreg==5) & (xrcomp==2 | xrcomp==3)) if parreg!=. & xrcomp!=.
label var compsch "competitive per \citet[p.129]{Schultz01} parreg2,5 and xrcomp2,3"
logit recip compsch reg1 demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog

regress reg1 compsch
predict reg1res, r /* Capture residuals */

regress compsch reg1
predict compres, r /* Capture residuals */

logit recip compsch reg1res demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog

logit recip compres reg1 demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog


*****************************************
* PREDICTED PROBABILITIES USING CLARIFY *
*****************************************

gen prrecip = .
gen prsd = .
gen regaxis = _n in 1/4

local m = 5000
quietly estsimp logit recip reg1 demano1 autano1 majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth, robust cluster(cwkeynum) nolog sims(`m')
setx mean

local r=1
foreach var of varlist reg1 demano1 autano1 {
	setx reg1 0 demano1 0 autano1 0
	setx `var' 1
	simqi, prval(1) genpr(pr) msims(`m')
	sum pr
	replace prrecip = r(mean) if regaxis==`r'
	replace prsd = r(sd) if regaxis==`r'
	drop pr
	local r = `r' + 1
}

/* Add in the autocratic category */
setx reg1 0 demano1 0 autano1 0
simqi, prval(1) genpr(pr) msims(`m')
sum pr
replace prrecip = r(mean) if regaxis==4
replace prsd = r(sd) if regaxis==4
drop pr

drop b1-b16

list prrecip prsd in 1/4 /* These values go to R ("fig1.R") */


*****************************************************
* ANALYSES USING DICHOTOMOUS MEASURE OF COMPETITION *
*****************************************************

gen comp = 0 if ht_partsz!=.
replace comp = 1 if ht_partsz<.55 & ht_partsz!=0 /* Zero values of ht_partsz are not meaningful */

gen mnopp = . /* Use this to capture means by category */

local m = 5000

* Democracies + CompAuth only
logit recip comp majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if (reg1==1 | demano1==1), robust cluster(cwkeynum) nolog
summ comp if e(sample)
replace mnopp = r(mean) in 1

* Democracies only
logit recip comp majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if reg1==1, robust cluster(cwkeynum) nolog
summ comp if e(sample)
replace mnopp = r(mean) in 2

* Competitive authoritarian only
logit recip comp majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if demano1==1, robust cluster(cwkeynum) nolog
summ comp if e(sample)
replace mnopp = r(mean) in 3

* Hegemonic authoritarian only
logit recip comp majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if autano1==1, robust cluster(cwkeynum) nolog
summ comp if e(sample)
replace mnopp = r(mean) in 4

list mnopp in 1/4 /* These values go to R ("fig2a.R") */

/* Do the same split samples as above, but generate predicted probabilities */
gen mnNO = . /* Mean for no opposition */
gen sdNO = . /* SD for no opposition */
gen mnOP = . /* Mean for opposition */
gen sdOP = . /* SD for opposition */

/* First do combined democratic + comp. authoritarian category */
quietly estsimp logit recip comp majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if (reg1==1 | demano1==1), robust cluster(cwkeynum) nolog sims(`m')
setx mean
setx comp 0
quietly simqi, prval(1) genpr(pr1)
setx comp 1
quietly simqi, prval(1) genpr(pr2)
drop b*
quietly summ pr1
replace mnNO = r(mean) in 1
replace sdNO = r(sd) in 1
quietly summ pr2
replace mnOP = r(mean) in 1
replace sdOP = r(sd) in 1

/* Then democracies only */
quietly estsimp logit recip comp majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if reg1==1, robust cluster(cwkeynum) nolog sims(`m')
setx mean
setx comp 0
quietly simqi, prval(1) genpr(pr3)
setx comp 1
quietly simqi, prval(1) genpr(pr4)
drop b*
quietly summ pr3
replace mnNO = r(mean) in 2
replace sdNO = r(sd) in 2
quietly summ pr4
replace mnOP = r(mean) in 2
replace sdOP = r(sd) in 2

/* Then competitive authoritarian only */
quietly estsimp logit recip comp majmaj minmaj majmin capshare1 contig s_wt_glo s_ld_1 s_ld_2 revter revgov revpol revoth if demano1==1, robust cluster(cwkeynum) nolog sims(`m')
setx mean
setx comp 0
quietly simqi, prval(1) genpr(pr5)
setx comp 1
quietly simqi, prval(1) genpr(pr6)
drop b*
quietly summ pr5
replace mnNO = r(mean) in 3
replace sdNO = r(sd) in 3
quietly summ pr6
replace mnOP = r(mean) in 3
replace sdOP = r(sd) in 3

list mnNO sdNO mnOP sdOP in 1/3 /* These values go to R ("fig2b.R") */



